home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- Module name: Utilities demo program.
-
- Author: Gareth Williams.
-
- Function: Demonstrates the PHIGS Debugger and PHIGS view editor.
-
- Modification history: (Version), (Date), (name), (Description).
-
- 1.0, 30th October 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathnames */
- #define LAMPSCRIPTNAME "../scripts/lamp.scr"
- #define CARDSCRIPTNAME "../scripts/postcard.scr"
- #define OPENWSNAME "../scripts/openws.scr"
-
- /*
- #ifdef VMS
- #define LAMPSCRIPTNAME "[-.scripts]lamp.scr"
- #define CARDSCRIPTNAME "[-.scripts]postcard.scr"
- #endif
- */
-
- static char *colwrd[] =
- {
- "BLACK", "WHITE", "GREEN",
- "BLUE", "CYAN", "GREY", "RED"
- };
-
- #define WS1 1
-
- static Pfloat devx, devy, devz;
- static ptkboolean docolour = FALSE;
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- Pint wst;
- Pint minid, maxid, lampid, white, black, green, grey, stid, stcom, lightblue;
- Ppoint pos, size;
- char ststr[20];
- Plimit echoarea;
- char commandstr[20], str[50];
- Pint lencom, lenstr, err, textfont;
- ptkboolean quit, useattrs;
- Pview_rep3 viewrep;
- Pint_list stids;
- Pws_st_tables lens;
-
- /* Implementation dependent code, open PHIGS and workstation */
- #if SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
-
-
- /* create the workstation type (tool)
- wst = phigs_ws_type_create( phigs_ws_type_x_tool,
- PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
- PHIGS_COLOUR_MODE, PHIGS_INDEX_COLOUR,
- PHIGS_X_BUF_MODE, PHIGS_BUF_DOUBLE_CMAP,
- PHIGS_COLOUR_TABLE_SIZE, 8,
- 0);
- if ( !wst )
- {
- pclose_phigs();
- exit(1);
- }
-
- popen_ws(WS1, (void *)NULL, wst);
- {
- Pws_st ws_state;
-
- pinq_ws_st(&ws_state);
- if (ws_state != PWS_ST_WSOP)
- exit(3);
- }
- */
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
-
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
-
- #ifdef SUN
- #ifndef SUNMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef HP
- #ifndef HPMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef PEXSI
- #ifndef PEXSIMONO
- docolour = TRUE;
- #endif
- #endif
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
-
- /* initialise hashtables */
- minid = 1;
- maxid = 500;
- ptk_inithashtables();
- ptk_createhashtable("structureid", minid, maxid);
- ptk_createhashtable("label", minid, maxid);
- ptk_createhashtable("colourindex", 1, maxid);
- ptk_createhashtable("viewindex", 1, maxid);
- ptk_createhashtable("windowid", 1, maxid);
- ptk_createhashtable("menuid", 1, maxid);
- ptk_createhashtable("name", 1, maxid);
- ptk_createhashtable("topologyid", 1, maxid);
-
- /* set colours */
- if (docolour)
- {
- ptk_setupcolourtable(WS1, 7, colwrd);
- green = ptk_stringtoint("colourindex", "green");
- grey = ptk_stringtoint("colourindex", "grey");
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- lightblue = ptk_stringtoint("colourindex", "blue");
-
- /* Implementation dependent code, choose a nice font */
- #ifdef SUN
- textfont = PFONT_TRIPLEX;
- #endif
- #ifndef SUN
- textfont = 1;
- #endif
- ptk_setbackgroundcolourind(WS1, grey);
- ptk_setdebuggerattrs(textfont, textfont, grey, black, grey, green,
- black, white, black, grey, black);
- ptk_setvieweditorattrs(textfont, textfont, grey, black, grey, green,
- black, white, black, grey, black);
- }
-
- /* read scripts */
- ptk_readphinterscript(LAMPSCRIPTNAME, NULL, NULL);
- ptk_readphinterscript(CARDSCRIPTNAME, NULL, NULL);
-
- stid = ptk_stringtoint("structureid", "lamp");
- stids.num_ints = 1;
- stids.ints = &stid;
-
- /* select debugger/ view */
-
- quit = FALSE;
- useattrs = TRUE;
- do
- {
- pset_loc_mode(WS1, 1, POP_REQ, PSWITCH_ECHO);
- pset_pick_mode(WS1, 1, POP_REQ, PSWITCH_ECHO);
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- ptk_readstring(WS1, "debugger", "Input command (default = debugger) >",
- &echoarea, 20, commandstr, &lencom);
- if (strncmp(commandstr, "debugger", lencom) == 0)
- {
- ptk_readstring(WS1, "lamp",
- "Input structure name (default = lamp) >",
- &echoarea, 50, str, &lenstr);
- stid = ptk_stringtoint("structureid", str);
- printf("Demonstrating the PHIGS debugger module of the PHIGS Toolkit...\n");
- ptk_debugger(WS1, stid);
- }
- else
- if (strncmp(commandstr, "view", lencom) == 0)
- {
- ptk_readstring(WS1, "lamp",
- "Input structure name (default = lamp) >",
- &echoarea, 50, str, &lenstr);
- printf("Demonstrating the PHIGS view editor module of the PHIGS Toolkit...\n");
- stid = ptk_stringtoint("structureid", str);
- ptk_vieweditor(WS1, &stids, &viewrep);
- }
- else if (strncmp(commandstr, "phinter", lencom) == 0)
- {
- ptk_callphinter();
- }
- else if (strncmp(commandstr, "help", lencom) == 0)
- {
- printf("utiltest options\n");
- printf("----------------\n");
- printf("debugger - start up PHIGS debugger\n");
- printf("view - start up PHIGS view editor\n");
- printf("phinter - call phinter\n");
- printf("quit - exit utiltest\n");
- }
- else if (strncmp(commandstr, "quit", lencom) == 0)
- {
- quit = TRUE;
- }
- else
- {
- printf("Command unknown\n");
- }
- pupd_ws(WS1, PFLAG_PERFORM);
- } while (quit == FALSE);
-
- pclose_ws(WS1); /* Close workstation. */
- pclose_phigs(); /* Close PHIGS. */
- }
-
- /*--------------------------------------------------------------------------*/
-